/**$(function(){
 * Created by Administrator on 2018/10/18.
 */

$(function(){
//控制菜单显隐

    menu();

});


function menu() {
    var nameId=sessionStorage.getItem("nameId");
    $.ajax({
        url: 'http://localhost:8081/queryUserInfo',//个人信息接口查询
        type: 'POST',
        dataType: 'json',
        contentType: "application/json",
        async: false,
        data: JSON.stringify({user:nameId}),
        xhrFields: {
            withCredentials: true
        },
        success: function (result) {
            console.log(result);
     if (result.data==null||result.data.userid==null){
         window.location.href="../login.html";
     }

        },
        error: function (result) {

            console.log(result);
        }
    });


    console.log(nameId);
    if(nameId==null||nameId==""||nameId==undefined){
        window.location.href="../login.html"
    }
    var obj = { user:nameId} ;
    $.ajax({
        url: 'http://localhost:8081/back_stage_management',//个人信息接口查询
        type: 'POST',
        dataType: 'json',
        contentType: "application/json",
        async: false,
        data: JSON.stringify(obj),
        xhrFields: {
            withCredentials: true
        },
        success: function (result) {

            console.log(result);
            var myli = "";

            if(result.data!=""&&result.data!=null&&result.data!=undefined){
            for(var i=0;i<result.data.length;i++) {
                myli += "<div class='subNav'>" + result.data[i].Map.module + "</div>";
                myli += "<ul class='navContent'>";
                for (var j=0;j<result.data[i].Map.List.length;j++){
                    myli+="<li class='waitWork' onclick='waitWork(\"" + result.data[i].Map.List[j].branchName + "\")'><a>" + result.data[i].Map.List[j].branchName + "</a></li>"
                }
                myli += "</ul>";
            }
            }
            $("#menu").html(myli);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log('XMLHttpRequest:');
            console.log(XMLHttpRequest);
        }
    });
    controller();
}
//局部刷新
var x="";
function waitWork(str){

   if (str=="预订机票"){
        x="firstPage.html";
       add_test();
   }else if(str=="查询航班"){
       x="secondPage.html";
       add_test();
   }



}

function add_test(){
    $.ajax({
        url : x,
        cache: false,
        timeout:1000,
        success:function(dates){
            //alert(dates);
            $("#mainContent").html(dates);//要刷新的div
        },
        error: function() {
            console.log("连接失败！");
        }
    });

}
//设置方法
function setting(){
    $.ajax({
        url : "SetMenu.html",
        cache: false,
        timeout:1000,
        success:function(dates){
            //alert(dates);
            $("#mainContent").html(dates);//要刷新的div
        },
        error: function() {
            console.log("连接失败！");
        }
    });
};
function controller() {


    $(".subNav").click(function(){

        $(this).toggleClass("currentDd").siblings(".subNav").removeClass("currentDd");
        $(this).toggleClass("currentDt").siblings(".subNav").removeClass("currentDt");
        $(this).next(".navContent").slideToggle(300).siblings(".navContent").slideUp(500);
    });
}

